<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据请求</title>
    <script src="../js/vue.js"></script>
    <script src="../js/axios.min.js"></script>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .table{
            width: 400px;
            margin: 50px auto;
        }
        .table .item{
            width: 100px;
            float: left;
            height: 40px;
            line-height: 40px;
            background-color: darkblue;
            color: darkgoldenrod;
            text-align: center;
        }
        .add input{
            width: 100px;
        }

    </style>
</head>
<body>
    <div id="app">
        <div class="table">
            <div class="add">
                用户名<input type="text" v-model="username">
                年龄<input type="text" v-model="userage">
                <button @click="add">新增</button>
            </div>
            <div class="tr">
                <div class="item">编号</div>
                <div class="item">姓名</div>
                <div class="item">年龄</div>
                <div class="item">操作</div>
            </div>
            <div class="tr" v-for = "item in list">
                <div class="item">{{item.id}}</div>
                <div class="item">{{item.username}}</div>
                <div class="item">{{item.userage}}</div>
                <div class="item" @click="del(item.id)">删除</div>
            </div>
        </div>   
    </div>
    
</body>
<script>
    new Vue({
        el : "#app",
        data : {
            list:[],
            username:"",
            userage:"",
        },
        methods:{
            async del(id){
                await axios({
                    method:"delete",
                    url:"http://localhost:2345/userinfos/"+id,
                })

                this.list = this.list.filter(item => item.id != id)
            },
            add(){
                
            }
        },
        created(){
            axios({
                method:"get",
                url:"http://localhost:2345/userinfos",
            }).then(
                (res) => {this.list = res.data;}
            )

        }

    })

</script>
</html>